package com.DAOTest;

import static org.junit.Assert.*;
import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.beans.Person;
import com.bussiness.AdminBussiness;
import com.dao.AdminDAO;
import com.utility.DBConnection;

public class AdminDAOTest extends TestCase{
	
	public AdminDAOTest()
	{
		super();
		System.out.println("i can execute");
	}

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testGetAllMembersByState() 
	{
		DBConnection dbcon = new DBConnection();
		
		Person[] allMemberList=null;
		String state="CA";
		
		AdminDAO AdminBI=new AdminDAO();		
		
		try
		{
			allMemberList=AdminBI.getAllMembersByState(state);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	
		Assert.assertEquals(state,allMemberList[0].getState());
	}
	@Test
	public void testGetAllMembersByState_1() {
	
		Person[] allMemberList=null;
		String state="AR";
		int value=0;
		
		AdminDAO AdminBI=new AdminDAO();		
		
		try
		{
			allMemberList=AdminBI.getAllMembersByState(state);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	
		int length=allMemberList.length;	
		for (int i=0;i<length;i++)
		{
			while (allMemberList[i].getState()!=state)
			{
				continue;
			}
			
			if (allMemberList[i].getState()==state)
				{
				value=i;
				break;
				}
			
		}
		Assert.assertEquals(0,length);
		
	}
	@Test
	public void testGetAllMembersByCity() {
		Person[] allMemberList=null;
		String city="San Jose";
		
		AdminDAO AdminBI=new AdminDAO();		
		
		try
		{
			allMemberList=AdminBI.getAllMembersByCity(city);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	
		Assert.assertEquals(city,allMemberList[0].getCity());
	}
	public void testGetAllMembersByCity_1() {
		Person[] allMemberList=null;
		String city="1213";
		
		AdminDAO AdminBI=new AdminDAO();		
		
		try
		{
			allMemberList=AdminBI.getAllMembersByCity(city);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		int length=allMemberList.length;
	
		Assert.assertEquals(0,length);
	}
	@Test
	public void testGetAllMembersByZip() 
	{

		Person[] allMemberList=null;
		int zip=95035;
		
		AdminDAO AdminBI=new AdminDAO();		
		
		try
		{
			allMemberList=AdminBI.getAllMembersByZip(zip);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	
		Assert.assertEquals(zip,allMemberList[0].getZipCode());
	}
	@Test
	public void testGetAllMembersByZip_1() 
	{
		Person[] allMemberList=null;
		int zip=95;
		
		AdminDAO AdminBI=new AdminDAO();		
		
		try
		{
			allMemberList=AdminBI.getAllMembersByZip(zip);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		int length=allMemberList.length;
	
		Assert.assertEquals(0,length);
	}

	@Test
	public void testGetAllMembersByFname() {
		
		Person[] allMemberList=null;
		String fname="Guest";
		
		AdminDAO AdminBI=new AdminDAO();		
		
		try
		{
			allMemberList=AdminBI.getAllMembersByFname(fname);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
	
		Assert.assertEquals(fname,allMemberList[0].getFirstName());
		}
	
	@Test
	public void testGetAllMembersByFname_1() {
		Person[] allMemberList=null;
		String fname="Rud@#@";
		
		AdminDAO AdminBI=new AdminDAO();
		
		try
		{
			allMemberList=AdminBI.getAllMembersByFname(fname);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		int length=allMemberList.length;
		
		Assert.assertEquals(0,length);	}
	

	@Test
	public void testGetAllMembersByLname() {
		Person[] allMemberList=null;
		String lname="User";
		
		AdminDAO AdminBI=new AdminDAO();
		
		try
		{
			allMemberList=AdminBI.getAllMembersByLname(lname);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	
		Assert.assertEquals(lname,allMemberList[0].getLastName());
	}

	@Test
	public void testGetAllMembersByLname_1() {
		Person[] allMemberList=null;
		String lname="Ashley34";
		
		AdminDAO AdminBI=new AdminDAO();
	
		try
		{
			allMemberList=AdminBI.getAllMembersByLname(lname);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		int length=allMemberList.length;

		Assert.assertEquals(0,length);	}

	@Test
	public void testGetAllPersonById() {
		Person allMemberList=null;
		long memid=1;
		
		AdminDAO AdminBI=new AdminDAO();
		
		try
		{
			allMemberList=AdminBI.getAllPersonById(memid);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}

		Assert.assertEquals(memid,allMemberList.getMemberShipNumber());
		}
	@Test
	public void testGetAllPersonById_1() 
	{
		Person allMemberList=null;
		long memid=2;
		
		AdminDAO AdminBI=new AdminDAO();	
		
		try
		{
			allMemberList=AdminBI.getAllPersonById(memid);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}

		Assert.assertEquals(null,allMemberList);
	}

}
